package com.ztgf.file.api.cms;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.StringUtils;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.sms.models.bo.SmsInfoQueryBO;
import com.ztgf.sms.models.dto.sms.SmsInfoDTO;
import com.ztgf.sms.models.service.ISmsInfoService;
import com.ztgf.sys.models.constant.SysConstant;
import com.ztgf.sys.models.dto.SysDictDTO;
import com.ztgf.sys.models.service.ISysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/cms/sms")
@Slf4j
@Api(value = "FileSmsController",tags = "短信")
public class FileSmsController {
    @DubboReference
    private ISmsInfoService iSmsInfoService;
    @DubboReference
    private ISysDictService iSysDictService;

    @ApiOperation(value = "短信查询",notes = "短信查询")
    @PostMapping("/queryPageList")
    public Result<Page<SmsInfoDTO>> queryChildUserPageList(SmsInfoQueryBO bo){
        Page<SmsInfoDTO> page = iSmsInfoService.queryAllPageList(bo);

        return new Result<>(page);
    }

    @ApiOperation(value = "获取通道资费(成都创信和玄武)",notes = "获取通道资费(成都创信和玄武)")
    @PostMapping(value = "/getAisleInfo")
    public Result getAisleInfo() throws Exception{
        return iSmsInfoService.getAisleInfo();
    }

    @ApiOperation(value = "更改中铁短信通道",notes = "更改中铁短信通道")
    @PostMapping(value = "/updateSmsAisle")
    public Result updateSmsAisle(String aisle){
        if (StringUtils.isEmpty(aisle)){
            return new Result(CodeEnum.FAIL_100002);
        }

        String name = SysConstant.SMS_USE_TYPE;
        SysDictDTO dictDTO = new SysDictDTO();
        dictDTO.setValue(aisle);
        Wrapper<SysDictDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("name", name);
        boolean flag = iSysDictService.update(dictDTO, wrapper);
        if (flag){
            return new Result();
        }else {
            return new Result(CodeEnum.FAIL);
        }
    }



}
